import Vue from 'vue'
import Vuex from 'vuex'

import {
  tbNetDiskQuery,
  tbNetDiskClear,
  tbNetDiskDownloadFile,
  tbNetDiskBatchBan,
  tbNetDiskBatchMoveNew,
  tbNetDiskBatchDelete,
  tbNetDiskBatchRecovery,
  tbNetDiskCreateDir,
  tbNetDiskUpdateDir,
  tbNetDiskBanDir,
  tbNetDiskDeleteDir,
  tbNetDiskRecoveryDir,
  tbNetDiskBan,
  tbNetDiskDelete,
  tbNetDiskRecovery,
  tbNetDiskUpdate,
} from '@/api/module/netDisk/netDisk'

Vue.use(Vuex)

const state = {}

const getters = {}

const actions = {
  //网盘查询
  async queryTbNetDisk({ commit }, listQuery) {
    let res = await tbNetDiskQuery({ ...listQuery })
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  //清空回收站
  async clearTbNetDisk({ commit }) {
    let res = await tbNetDiskClear()
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  //下载文件
  async downloadFileTbNetDisk({ commit }, id) {
    let res = await tbNetDiskDownloadFile(id)
    return res.data
  },
  //批量假删文件
  async batchBanTbNetDisk({ commit }, data) {
    let res = await tbNetDiskBatchBan(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  //批量彻底删除文件
  async batchDeleteTbNetDisk({ commit }, data) {
    let res = await tbNetDiskBatchDelete(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  //批量恢复
  async batchRecoveryTbNetDisk({ commit }, data) {
    let res = await tbNetDiskBatchRecovery(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  //新批量移动，数组对象集合
  async batchMoveNewTbNetDisk({ commit }, data) {
    let res = await tbNetDiskBatchMoveNew(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  //------------------------- 文件夹方法 ---------------------
  //假删除文件夹
  async banDirTbNetDisk({ commit }, row) {
    let res = await tbNetDiskBanDir(row.id)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  //恢复文件夹
  async recoveryDirTbNetDisk({ commit }, row) {
    let res = await tbNetDiskRecoveryDir(row.id)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  //彻底删除文件夹
  async deleteDirTbNetDisk({ commit }, row) {
    let res = await tbNetDiskDeleteDir(row.id)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  //创建文件夹
  async createDirTbNetDisk({ commit }, data) {
    let res = await tbNetDiskCreateDir(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  //修改文件夹
  async updateDirTbNetDisk({ commit }, data) {
    let res = await tbNetDiskUpdateDir(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  //------------------------- 文件方法 -----------------------
  //编辑文件
  async updateTbNetDisk({ commit }, data) {
    let res = await tbNetDiskUpdate(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  //假删除文件
  async banTbNetDisk({ commit }, data) {
    let res = await tbNetDiskBan(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  //恢复文件
  async recoveryTbNetDisk({ commit }, data) {
    let res = await tbNetDiskRecovery(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  //彻底删除文件
  async deleteTbNetDisk({ commit }, row) {
    let res = await tbNetDiskDelete(row.id)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
}

const mutations = {}

export default {
  state,
  getters,
  actions,
  mutations,
}
